<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\Author;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class AuthorController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Author(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('name');
            $grid->column("order_number")->editable()->sortable();
//            $grid->column("is_show")->
            $grid->column('状态')->switchGroup(["is_show"]);
//            $grid->img()->image();
//            $grid->column('description');
//            $grid->column('created_at');
//            $grid->column('updated_at')->sortable();
            // 也可以这样
            $grid->disableBatchDelete();
            $grid->filter(function (Grid\Filter $filter) {
                $filter->like('name');
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Author(), function (Show $show) {
            $show->field('id');
            $show->field('name');
            $show->img()->image();
            $show->pc_img("PC头像")->image();
            $show->field('description')->unescape();
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Author(), function (Form $form) {
            $form->display('id');
            $form->text('name');
//            $form->text("position")->help("作家职务，多个用英文,隔开");
            $form->number("order_number");
            $form->switch("is_show");
            $form->image("img")->uniqueName()->autoUpload();
            $form->image("pc_img","pc端头像")->uniqueName()->autoUpload();
            $form->editor("description")->required();
            $form->editor("introduction")->help("大师介绍，大师个人中心中的简介，为空的话采用‘作家描述’的内容");
//                ->text('description');
        });
    }
}
